package com.czxy.blogs.manage.web.controller;

import com.czxy.blogs.domain.Part1;
import com.czxy.blogs.manage.service.PartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/part")
public class PartController {

    @Autowired
    private PartService partService;


    @RequestMapping("/findAllPart")
    public String findAllPart(Model model){

        List<Part1> partList = partService.findAllPart();
        model.addAttribute("partList",partList);
        return "category";

    }

    @RequestMapping("/showPart")
    public String showPart(@RequestParam("pid") String pid, Model model){
        Part1 part = partService.view(pid);
        model.addAttribute("part",part);
        return "update-category";
    }

    @RequestMapping("/updatePart")
    public String updatePart(Part1 part){
        System.out.println(part);
        partService.updatePart(part);
        return "forward:/part/findAllPart.action";
    }

    @RequestMapping("/deletePart")
    public String deletePart(String id){
        partService.deletePart(id);
        return "forward:/part/findAllPart.action";
    }

    @RequestMapping("/addPart")
    public String addPart(Part1 part){
        partService.addPart(part);
        return "forward:/part/findAllPart.action";
    }
}
